[java] tcp socket communication [send and recieve help]

Posted by raven on Stack Overflow See other posts from Stack Overflow or by raven
Published on 2010-05-09T15:54:19Z Indexed on 2010/05/09 15:58 UTC
Read the original article Hit count: 178

Filed under:
|
|
|
|

hello, I am creating a Chat in java. I have a method (onMouseRelease) inside an object that creates a tcp server and waits for a socket

 ServerSocket server = new ServerSocket(port);
     Socket channel = server.accept();

now I want to make a thread that will loop and read data from the socket, so that once the user on the other side sent me a string, I will extract the data from the socket [or is it called packet? sry I am new to this], and update a textbox to add the additional string from the socket [or packet?].

I have no idea how to READ (extract) the information from the scoket [/packet] and then update it into a JTextArea which is called userOutput. And how to Send a string to the other client, so that it will also could read the new data and update its JTextArea. (from what I know, for a 2 sided tcp communication you need one computer to host a server and the other to connect [as a client] and once the connection is set the client can also recieve new information from the socket. Is that true? and please tell me how )

Any help appreciated !! I know this is abit long but I have searched allot and didn't understand [I saw something like printwriter but failed to understand].

© Stack Overflow or respective owner

Related posts about java

Related posts about socket